﻿using HeyPiPi_Desk.Domain;
using HeyPiPi_Desk.Models;
using HeyPiPi_Desk.Tools;
using HeyPiPi_Desk.ViewModels;
using LibrarySystem.Tools;
using MaterialDesignThemes.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace HeyPiPi_Desk.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private MainWindowViewModel mv = null;
        public MainWindow()
        {
            InitializeComponent();
         this.mv   =new MainWindowViewModel();
            this.DataContext = mv;
            this.mv.TreeView = this.treemenu;

            GlobalSetting.GetGlobalSetting().SendMessageEvent += (content) =>
            {

                MainSnackbar.MessageQueue.Enqueue(content,true);
               

            };

        
        }


        private void ClosingEventHandler(object sender, DialogClosingEventArgs eventArgs)
        {
            //this.bodyContainer.Content = this.mv.DemoItems[0].Content;
        //    Application.Current.Shutdown();
        }


        private void UIElement_OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
           
            //until we had a StaysOpen glag to Drawer, this will help with scroll bars
            //var dependencyObject = Mouse.Captured as DependencyObject;
            //while (dependencyObject != null)
            //{
            //    if (dependencyObject is ScrollBar) return;
            //    dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
            //}
            if (Mouse.Captured is ListBox listBox)
            {
            
            }

           MenuToggleButton.IsChecked = false;
        }

        private async void MenuPopupButton_OnClick(object sender, RoutedEventArgs e)
        {
            var sampleMessageDialog = new SampleMessageDialog
            {
                Message = { Text = ((ButtonBase)sender).Content.ToString() }
            };

            await DialogHost.Show(sampleMessageDialog, "RootDialog");
        }

        private async void SafeLogoutEvent(object sender, RoutedEventArgs e)
        {
            var sampleMessageDialog = new SampleMessageDialog
            {

                //todo:清空一些内容

                Message = { Text = "退出成功" }

               
            };

           object x=  await DialogHost.Show(sampleMessageDialog, "RootDialog");
            this.Close();
        }

        private void MyInfoSetting_Event(object sender, RoutedEventArgs e)
        {
            this.bodyContainer.Content = new MyInfoView();
        }

        private void OpenSetting_Event(object sender, RoutedEventArgs e)
        {
            this.bodyContainer.Content = new SettingView();
        }

        private  void Window_loaded(object sender, EventArgs e)
        {
            //let's set up a little MVVM, cos that's what the cool kids are doing:
            var view = new LoginDialog();
            //show the dialog
            var result =  DialogHost.Show(view, "RootDialog", ClosingEventHandler);
        }


    }
}
